
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';

class MyLocationsLanguaeDelegates extends LocalizationsDelegate<MyLocationsLanguages>{

  /// 创建默认构造器
  const MyLocationsLanguaeDelegates();
  // 创建静态构造
  static MyLocationsLanguaeDelegates delegates = new MyLocationsLanguaeDelegates();


  @override
  bool isSupported(Locale locale) {
    // 判断是否支持
    return ['en','zh','he'].contains(locale.languageCode);
  }
  @override
  Future <MyLocationsLanguages>load(Locale locale) {
    // 异步初始化 MyLocationsLanguages
   return  SynchronousFuture(MyLocationsLanguages(locale));
  }
  @override
  bool shouldReload(covariant LocalizationsDelegate old) {
    // 是否需要重哉
    return false;
  }
}

// 定义程序 多语言适配
class MyLocationsLanguages {
  // 记录当前应用程序使用到本地化配置
  final Locale locale;

  MyLocationsLanguages(this.locale);
  // 定义一个静态方法来初始化 MyLocationsLanguaeDelegates
  static of(BuildContext context){
    return Localizations.of(context, MyLocationsLanguages);
  }

  static Map<String ,Map<String ,String>> localValue = {
    // 英文
    'en':{
      'task title':'Flutter Demo',
      'titleBar title':'Flutter Demo Home Page',
      'click tip':'You have pushed the button this many times',
      'inc':'Increment',
      'click button':'click select language',
      'welcomes':'China welcome you',
      'button1':'china Language',
      'button2':'English Language',
      'button3':'Spain Language'
    },
    // 中文
    'zh':{
      'task title':'Flutter 示例',
      'titleBar title':'Flutter 示例主页面',
      'click tip':'你一共点击了这么多次按钮',
      'inc':'增加',
      'click button':'点击切换',
      'welcomes':'中国欢迎你',
      'button1':'简体中文',
      'button2':'英文',
      'button3':'西班牙语'
    },
    // 西班牙
    'he':{
      'task title':'Ejemplo de Flutter',
      'titleBar title':'Flutter 示例主页面',
      'click tip':'has hecho clic en los bottones tants veces en total',
      'inc':'增加',
      'click button':'Hage clic en cambiar',
      'welcomes':'Bienvenido a china',
      'button1':'chino simplificado',
      'button2':'ingies',
      'button3':'Linares'
    }
  };

  get button1{
    return localValue[locale.languageCode]['button1'];
  }
  get button2{
    return localValue[locale.languageCode]['button2'];
  }
  get button3{
    return localValue[locale.languageCode]['button3'];
  }
}

